import 'package:flutter/material.dart';

// ignore: must_be_immutable
class MyDialog extends Dialog {
  String title;
  late String content;
  late Function()? onPress;
  MyDialog({super.key, required this.title, this.content = '内容', this.onPress});

// 继承Dialog类之后，要重写build方法，返回的是一个widget
  @override
  Widget build(BuildContext context) {
    return Material(
        // 设置背景透明
        type: MaterialType.transparency,
        // center得目的是不让这个弹框铺满屏
        child: Center(
          child: Container(
            height: 300,
            width: 300,
            color: Colors.white,
            child: Column(
              children: [
                Padding(
                  padding: const EdgeInsets.all(5),
                  child: Stack(
                    children: [
                      Align(
                        alignment: Alignment.centerLeft,
                        child: Text(
                          title,
                          style: const TextStyle(fontSize: 18),
                        ),
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        // InkWell可以给标签绑定点击事件
                        child: InkWell(
                            onTap: onPress, child: const Icon(Icons.close)),
                      )
                    ],
                  ),
                ),
                const Divider(),
                Container(
                  padding: const EdgeInsets.all(10),
                  width: double.infinity,
                  child: Text(content),
                )
              ],
            ),
          ),
        ));
  }
}
